package cc.sheji.Service;


import cc.sheji.domain.Ad;
import cc.sheji.domain.AdQueryCriteria;
import cc.sheji.domain.PersonAuth;
import cc.sheji.domain.PersonAuthQueryCriteria;
import cc.sheji.reposity.AdRepository;
import cc.sheji.reposity.PersonAuthRepository;
import cc.sheji.util.QueryHelp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class PersonAuthService {

    @Autowired
    PersonAuthRepository adRepository;

    public PersonAuth create(PersonAuth entity) {
        entity = adRepository.save(entity);
        return entity;
    }

    public PersonAuth get(Long id) {
        PersonAuth entity = adRepository.findById(id).get();
        return entity;
    }

    public boolean delete(long id){
        PersonAuth ad = adRepository.findById(id).get();
        ad.setDeleted(1);
        adRepository.save(ad);
        return true;
    }

    public PersonAuth update(PersonAuth entity) {
        System.out.println(entity);
        entity = adRepository.save(entity);
        return entity;
    }

    public List<PersonAuth> list(PersonAuthQueryCriteria criteria, Pageable pageable) {
        Page<PersonAuth> page = adRepository.findAll((root, criteriaQuery, criteriaBuilder) ->
                QueryHelp.getPredicate(root, criteria, criteriaBuilder), pageable);
        return page.getContent();
    }
}
